package com.oba.base.service;

import com.oba.base.dao.BaseDao;
import com.oba.base.interfaces.IBaseBo;

/**
 * 业务对象维护服务
 */
public abstract class BaseService<Tbo extends IBaseBo, Tdao extends BaseDao> {
	private Tdao dao;

	public Tdao getDao() {
		return dao;
	}

	public void setDao(Tdao dao) {
		this.dao = dao;
	}

	public void del(IBaseBo bo) {
		getDao().delete(bo);

	}

	public void save(IBaseBo bo) {
		getDao().save(bo);
	}

	public IBaseBo reLoad(IBaseBo bo) {
		return getDao().load(bo.getClass(), bo.getId());
	}

	protected Tbo getNewBo() {
		try {
			Tbo bo = getBoClass().newInstance();
			bo.setNewBo(Boolean.TRUE);
			return bo;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	protected abstract Class<Tbo> getBoClass();

}